//
//  LFNavBasicViewController.m
//  QingDaoCommunity
//
//  Created by 李学林 on 15/11/21.
//  Copyright © 2015年 teteTechnology. All rights reserved.
//

#import "LFNavBasicViewController.h"

#define kBtnWidth 44
#define kBtnHeight 44
@interface LFNavBasicViewController ()




@end

@implementation LFNavBasicViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreemWidth, kNavHeitht)];

    self.navView.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:_navView];
    
    //添加左边的按钮
    self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    self.leftBtn.frame = CGRectMake(0, kStateBarHeight , kBtnWidth, kBtnHeight);
    
    [self.leftBtn addTarget:self action:@selector(backMethod) forControlEvents:UIControlEventTouchUpInside];
    
    [self.leftBtn setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
    
    [self.navView addSubview:_leftBtn];
    
    // 创建title
    self.titleLab = [[UILabel alloc]initWithFrame:CGRectMake(kBtnWidth , kStateBarHeight, kScreemWidth - 2*kBtnWidth, kBtnHeight)];
    
    self.titleLab.text = @"首页";
    self.titleLab.textAlignment = NSTextAlignmentCenter;
    self.titleLab.font = [UIFont systemFontOfSize:19];
    
    [self.navView addSubview:_titleLab];
    
    //添加右边的按钮
    self.rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(kScreemWidth - kBtnWidth , kStateBarHeight , kBtnWidth, kBtnHeight)];
    
    [self.rightBtn addTarget:self action:@selector(loginMethod) forControlEvents:UIControlEventTouchUpInside];
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeRightStateToImage) name:@"LoginSuccess" object:nil];

    // 从偏好设置中判断

    BOOL rememberPwd = [[NSUserDefaults standardUserDefaults] boolForKey:@"rememberPwd"];
    
    
    if (rememberPwd) {
        // 将偏好设置中的账号密码填充到
        
        
        //调用登录按钮
        
        
        //改变右上角的图标
        [self changeRightStateToImage];
        
    }else{
        
        [self.rightBtn setTitle:@"登录/注册" forState:UIControlStateNormal];
        
        self.rightBtn.frame = CGRectMake(kScreemWidth - 2 * kBtnWidth,kStateBarHeight, kBtnWidth, kBtnHeight);
        
        [self.rightBtn sizeToFit];
    }
    
    [self.navView addSubview:_rightBtn];
}


- (void)changeRightStateToImage{

    [self.rightBtn setTitle:nil forState:UIControlStateNormal];
    
    self.rightBtn.frame = CGRectMake(kScreemWidth - kBtnWidth,kStateBarHeight, kBtnWidth, kBtnHeight);
    
    [self.rightBtn setImage:[UIImage imageNamed:@"nav_user"] forState:UIControlStateNormal];

    [self.rightBtn sizeToFit];
    
//    self.rightBtn.enabled = NO;

}


- (void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:YES];
    
    self.navigationController.navigationBar.hidden = YES; 



}


- (void)backMethod{


}
- (void)loginMethod{



}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
